class DinnermomentsController < ApplicationController
  # GET /dinnermoments
  # GET /dinnermoments.xml
  def index
    @dinnermoments = Dinnermoment.find(:all)
    @users = User.find(:all)

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @dinnermoments }
    end
  end

  # GET /dinnermoments/1
  # GET /dinnermoments/1.xml
  def show
    @dinnermoment = Dinnermoment.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @dinnermoment }
    end
  end

  # GET /dinnermoments/new
  # GET /dinnermoments/new.xml
  def new
    @dinnermoment = Dinnermoment.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @dinnermoment }
    end
  end

  # GET /dinnermoments/1/edit
  def edit
    @dinnermoment = Dinnermoment.find(params[:id])
    @users = @dinnermoment.users.find(:all)
  end

  # POST /dinnermoments
  # POST /dinnermoments.xml
  def create
    @dinnermoment = Dinnermoment.new(params[:dinnermoment])

    respond_to do |format|
      if @dinnermoment.save
        flash[:notice] = 'Dinnermoment was successfully created.'
        format.html { redirect_to(@dinnermoment) }
        format.xml  { render :xml => @dinnermoment, :status => :created, :location => @dinnermoment }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @dinnermoment.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /dinnermoments/1
  # PUT /dinnermoments/1.xml
  def update
    @dinnermoment = Dinnermoment.find(params[:id])
    @dinnermoment.kook = params[:user][:id]

    respond_to do |format|
      if @dinnermoment.update_attributes(params[:dinnermoment])
        flash[:notice] = 'Dinnermoment was successfully updated.'
        format.html { redirect_to(@dinnermoment) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @dinnermoment.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /dinnermoments/1
  # DELETE /dinnermoments/1.xml
  def destroy
    @dinnermoment = Dinnermoment.find(params[:id])
    @dinnermoment.destroy

    respond_to do |format|
      format.html { redirect_to(dinnermoments_url) }
      format.xml  { head :ok }
    end
  end
  
  def addEater
    @dinnermoment = Dinnermoment.find(params[:id])
    @eater = User.find(params[:user])
    #@eater = @dinermoment.users.create!(user)
   	
    @dinnermoment.users << @eater
    #redirect_to @dinermoment
    render :update do |page|
    	page.replace_html "moment#{@dinnermoment.id}", :partial => @dinnermoment
    end
  end
end